package com.imooc.ad.exception;

import com.imooc.ad.vo.CommonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 *  统一异常处理
 */

@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = AdException.class)
    public CommonResponse<String> handleAdException(HttpServletRequest request,
                                                    AdException ex){
        CommonResponse<String> response = new CommonResponse<String>(-1,"BUSINESS ERROR");
        response.setData(ex.getMessage());
        return response;
    }
}
